var net = require('net');
var fs = require('fs')
var readline = require('readline');
var path = __dirname + '/../base';

var client = new net.Socket();
client.connect(8002, '127.0.0.1', function () {

    var data = fs.readFileSync(path + '/' + '7_188002.txt');
    var dataArr = data.toString().split('\n');
    var i = 0

    var setTime = setInterval(function () {
        client.write(dataArr[i])
        i++;
        if (i === dataArr.length) {
            clearInterval(setTime)
        }
    }, 1000)

    // var lines = []
    // var myInterface = readline.createInterface({
    //     input: fs.createReadStream(path + '/' + "7_188002.txt")
    // });
    // myInterface.on('line', function (line) {
    //     var index = line.split(',');
    //     if(line.indexOf("GGA")!==-1){
    //         lines.push(line)
    //     }
    // });
    // myInterface.on('close', function () {
    //     var i = 0
    //
    //     var setTime = setInterval(function () {
    //         client.write(lines[i])
    //         i++;
    //         if (i === lines.length) {
    //             clearInterval(setTime)
    //         }
    //     }, 1000)
    // })
    // client.write('Hello, server! Love, Client.');
});

client.on('data', function (data) {
    console.log('Received: ' + data);
    // client.destroy();
});

client.on('close', function () {
    console.log('Connection closed');
});